package com.xiaoxu.scala_base.三班

/**
  *
  * author: zhangXu
  * createTime: 2018-12-07 19:02
  **/
object _010FunctionApp {

  def main(args: Array[String]): Unit = {
    sayHello()
    sayHello
    sayHello("gaobo")
    sayHi()
    sayHi("xiaohZang")
    println(price(100, 10))
    println(price(100, 10))
    //了解
    println(price(count = 10, money = 100))
    sum(1,2,3)
    sum(1,2,3,4,5,6)

    val a = 1;
    if(a>0){
      true
    }else{
      false
    }


  }

  def sum(x: Int, y: Int): Int = {
    x + y //最后一行就是返回值
  }

  def sayHello(): Unit = {
    println("hello everybody")
  }

  def sayHello(name: String): Unit = {
    println(name)
  }

  //默认参数
  def sayHi(name: String = "zhangSan"): Unit = {
    println(name)
  }

  //使用时,通过名字传入参数，与定义顺序无关
  def price(money: Double, count: Double): Double = {
    money / count
  }

  def sum(x: Int, y: Int, z: Int): Int = {
    x + y + z
  }

  def sum(numbers: Int*): Int = {
    var result = 0
    for (number <- numbers) {
      result += number
    }
    result
  }
}
